package org.vnl.platform.impl.orm;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;
import org.vnl.platform.orm.ORMEnvCode;
import org.vnl.platform.orm.TransactionException;
//import org.apache.log4j.Logger;


public class TransactionDescriptor {
//    private static final Logger logger = Logger.getLogger(TransactionDescriptor.class);
    
    private static TransactionDescriptor instance;
    
    private HashMap<String, String> sqlPool;
    
    private TransactionDescriptor() {
        sqlPool = new HashMap<String, String>();
    }
    
    public static TransactionDescriptor getInstance() {
        if (instance == null) {
            instance = new TransactionDescriptor();
        }
        return instance;
    }
    
    /**
     * 取出交易代號的SQL
     * 
     * @param tid
     * @return
     */
    public String getSQL(String tid) {
        String sql = sqlPool.get(tid);
        if (StringUtils.isBlank(sql)) {
            throw new TransactionException(ORMEnvCode.ERR_TRANSACTION_ID_NOT_SUPPORT, new Object[] { tid });
        }
        return sql;
    }
}
